import {
  queryStockIndexRealInfo,
  queryStockSectorRealInfo,
  queryOpenFundIndexRealInfo,
  addUserStock,
  queryUserStockListRealInfo,
  queryUserStockKlineGraphicViewInfo
} from '@/api/stock/stock'

const actions = {
  queryStockIndexRealInfo({commit, state}) {
    return new Promise((resolve, reject) => {
      queryStockIndexRealInfo().then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryStockSectorRealInfo({commit, state}) {
    return new Promise((resolve, reject) => {
      queryStockSectorRealInfo().then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryOpenFundIndexRealInfo({commit, state}) {
    return new Promise((resolve, reject) => {
      queryOpenFundIndexRealInfo().then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  addUserStock({commit, state}, stock) {
    return new Promise((resolve, reject) => {
      addUserStock(stock).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserStockListRealInfo({commit, state}, uid) {
    return new Promise((resolve, reject) => {
      queryUserStockListRealInfo(uid).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  },

  queryUserStockKlineGraphicViewInfo({commit, state}, data) {
    const {code, type} = data;
    return new Promise((resolve, reject) => {
      queryUserStockKlineGraphicViewInfo(code, type).then(resp => {
        resolve(resp);
      }).catch(err => {
        reject(err);
      })
    })
  }
}

export default {
  actions
}
